home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Messenger.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  48.3 KB  |  1,547 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > Messenger functions
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 26th February 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new Messenger;
  26.  
  27. class Messenger {
  28.  
  29.     var $output     = "";
  30.     var $page_title = "";
  31.     var $nav        = array();
  32.     var $html       = "";
  33.     var $email      = "";
  34.     
  35.     var $msg_stats  = array();
  36.     var $prefs      = "";
  37.     
  38.     var $member     = array();
  39.     var $m_group    = array();
  40.     
  41.     var $to_mem     = array();
  42.     
  43.     var $jump_html  = "";
  44.     
  45.     var $vid        = "in";
  46.     var $mem_groups = array();
  47.     var $mem_titles = array();
  48.     
  49.     var $parser     = "";
  50.     
  51.     var $cp_html    = "";
  52.     
  53.     function Messenger() {
  54.         global $ibforums, $DB, $std, $print;
  55.         
  56.         //--------------------------------------------
  57.         // Make sure our code number is numerical only
  58.         //--------------------------------------------
  59.         
  60.         if ($ibforums->input['CODE'] == "") $ibforums->input['CODE'] = 00;
  61.         
  62.         //--------------------------------------------
  63.         // Require the HTML and language modules
  64.         //--------------------------------------------
  65.         
  66.         $ibforums->lang = $std->load_words($ibforums->lang, 'lang_msg', $ibforums->lang_id);
  67.         $ibforums->lang = $std->load_words($ibforums->lang, 'lang_ucp'   , $ibforums->lang_id);
  68.         
  69.         //--------------------------------------------
  70.         
  71.         require "./Skin/".$ibforums->skin_id."/skin_msg.php";
  72.         
  73.         $this->html = new skin_msg();
  74.         
  75.         //--------------------------------------------
  76.         
  77.         require "./Skin/".$ibforums->skin_id."/skin_ucp.php";
  78.         
  79.         $this->cp_html = new skin_ucp();
  80.         
  81.         //--------------------------------------------
  82.         
  83.         $this->base_url        = "{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}?s={$ibforums->session_id}";
  84.         $this->base_url_nosess = "{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}";
  85.         
  86.         //--------------------------------------------
  87.         // Check viewing permissions, etc
  88.         //--------------------------------------------
  89.         
  90.         $this->member  = $ibforums->member;
  91.         
  92.         if (empty($this->member['g_use_pm'])) {
  93.             $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_use_messenger' ) );
  94.         }
  95.         
  96.         if (empty($this->member['id'])) {
  97.             $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_guests' ) );
  98.         }
  99.         
  100.         //--------------------------------------------
  101.         // Get the member stats data
  102.         //--------------------------------------------
  103.         
  104.         $DB->query("SELECT vdirs, msg_total, new_msg, msg_msg_id FROM ibf_members WHERE id='".$this->member['id']."'");
  105.         $this->msg_stats = $DB->fetch_row();
  106.         
  107.         //--------------------------------------------
  108.         // Do a little set up, do a litle dance, get
  109.         // down tonight! *boogie*
  110.         //--------------------------------------------
  111.         
  112.         $this->jump_html = "<select name='VID' class='forminput'>\n";
  113.         
  114.         $this->msg_stats['dir_data'] = array();
  115.         
  116.         // Do we have VID?
  117.         // No, it's just the way we walk! Haha, etc.
  118.         
  119.         if ($ibforums->input['VID'])
  120.         {
  121.             $this->vid = $ibforums->input['VID'];
  122.         }
  123.         
  124.         if (empty($this->msg_stats['vdirs']))
  125.         {
  126.             $this->msg_stats['vdirs'] = "in:Inbox|sent:Sent Items";
  127.         }
  128.         
  129.         
  130.         foreach( explode( "|", $this->msg_stats['vdirs'] ) as $dir )
  131.         {
  132.             list ($id, $real) = explode( ":", $dir );
  133.             
  134.             if (empty($id))
  135.             {
  136.                 continue;
  137.             }
  138.             
  139.             $this->msg_stats['dir_data'][] = array( 'id' => $id, 'real' => $real );
  140.             
  141.             if ($this->vid == $id)
  142.             {
  143.                 $this->msg_stats['current_dir'] = $real;
  144.                 $this->msg_stats['current_id']  = $id;
  145.                 $this->jump_html .= "<option value='$id' selected>$real</option>\n";
  146.             }
  147.             else
  148.             {
  149.                 $this->jump_html .= "<option value='$id'>$real</option>\n";
  150.             }
  151.         }
  152.         
  153.         $this->jump_html .= "<!--EXTRA--></select>\n\n";
  154.         
  155.         
  156.         
  157.         $print->add_output( $this->cp_html->Menu_bar($this->base_url) );;
  158.         
  159.         
  160.         //--------------------------------------------
  161.         // What to do?
  162.         //--------------------------------------------
  163.         
  164.         
  165.         switch($ibforums->input['CODE']) {
  166.             case '01':
  167.                 $this->msg_list();
  168.                 break;
  169.             case '02':
  170.                 $this->contact();
  171.                 break;
  172.             case '03':
  173.                 $this->view_msg();
  174.                 break;
  175.             case '04';
  176.                 $this->send();
  177.                 break;
  178.             case '05':
  179.                 $this->delete();
  180.                 break;
  181.             case '06':
  182.                 $this->multi_act();
  183.                 break;
  184.             case '07':
  185.                 $this->prefs();
  186.                 break;
  187.             case '08':
  188.                 $this->do_prefs();
  189.                 break;
  190.             case '09':
  191.                 $this->add_member();
  192.                 break;
  193.             case '10':
  194.                 $this->del_member();
  195.                 break;
  196.             case '11':
  197.                 $this->edit_member();
  198.                 break;
  199.             case '12':
  200.                 $this->do_edit();
  201.                 break;
  202.             case '14':
  203.                 $this->archive();
  204.                 break;
  205.             case '15':
  206.                 $this->do_archive();
  207.                 break;
  208.             case '99':
  209.                 $this->pm_popup();
  210.                 break;
  211.             default:
  212.                 $this->msg_list();
  213.                 break;
  214.         }
  215.         
  216.         // If we have any HTML to print, do so...
  217.         
  218.         $fj = $std->build_forum_jump();
  219.         $fj = preg_replace( "!#Forum Jump#!", $ibforums->lang['forum_jump'], $fj);
  220.         
  221.         $this->output .= $this->cp_html->CP_end();
  222.         
  223.         $this->output .= $this->cp_html->forum_jump($fj);
  224.         
  225.         $print->add_output("$this->output");
  226.         $print->do_output( array( 'TITLE' => $this->page_title, 'JS' => 0, NAV => $this->nav ) );
  227.             
  228.      }
  229.      
  230.      /**********************************************************/
  231.      // PM Pop up:
  232.      //
  233.      // Simpy display the pop up window
  234.      /**********************************************************/
  235.      
  236.      function pm_popup() {
  237.      
  238.          global $DB, $std, $print, $ibforums;
  239.          
  240.          // Get the last message stuff
  241.          
  242.          $DB->query("SELECT m.name, msg.title, msg.msg_date, msg.from_id FROM ibf_members m, ibf_messages msg ".
  243.                     "WHERE msg.member_id='".$ibforums->member['id']."' AND msg_id='".$this->msg_stats['msg_msg_id']."' ".
  244.                     "AND m.id=msg.from_id");
  245.                     
  246.          $row = $DB->fetch_row();
  247.                     
  248.          // Fix up the text string...
  249.          
  250.          $row['msg_date'] = $std->get_date( $row['msg_date'], 'LONG' );
  251.          
  252.          $text = preg_replace( "/<#NAME#>/" , $row['name']    , $ibforums->lang['pmp_string'] );
  253.          $text = preg_replace( "/<#TITLE#>/", $row['title']   , $text );
  254.          $text = preg_replace( "/<#DATE#>/" , $row['msg_date'], $text );
  255.          
  256.          $html = $this->html->pm_popup($text);
  257.          
  258.          $print->pop_up_window( "PM", $html );
  259.      
  260.      }
  261.      
  262.      
  263.      /**********************************************************/
  264.      // ARCHIVE:
  265.      //
  266.      // Allows a user to archive and email a HTML file
  267.      /**********************************************************/
  268.      
  269.      function archive() {
  270.          global $ibforums, $DB, $std, $print;
  271.          
  272.          $this->jump_html = preg_replace("/<!--EXTRA-->/", "<option value='all'>".$ibforums->lang['all_folders']."</option>", $this->jump_html );
  273.          
  274.          $this->output .= $this->html->archive_form( $this->jump_html );
  275.          
  276.          $this->page_title = $ibforums->lang['t_welcome'];
  277.          $this->nav        = array( "<a href='".$this->base_url."&act=UserCP&CODE=00'>".$ibforums->lang['t_title']."</a>" );
  278.          
  279.      }
  280.      
  281.      function do_archive() {
  282.          global $ibforums, $DB, $std, $print;
  283.          
  284.          require "./sources/lib/emailer.php";
  285.         
  286.         $this->email = new emailer();
  287.          
  288.          //----------------------------------------
  289.          // Did we specify a folder, or choose all?
  290.          //----------------------------------------
  291.          
  292.          $folder_query  = "";
  293.          $msg_ids       = array();
  294.          
  295.          if ($ibforums->input['VID'] != 'all')
  296.          {
  297.              $folder_query = " AND vid='".$ibforums->input['VID']."'";
  298.          }
  299.          
  300.          if ( $ibforums->input['dateline'] == 'all' )
  301.          {
  302.              $time_cut = 0;
  303.          }
  304.          else
  305.          {
  306.              $time_cut = time() - ($ibforums->input['dateline'] * 60 * 60 *24);
  307.          }
  308.          
  309.          //----------------------------------------
  310.          // Check the input...
  311.          //----------------------------------------
  312.          
  313.          $ibforums->input['number'] = preg_replace( "/^(\d+)$/", "\\1", $ibforums->input['number'] );
  314.          
  315.          if ($ibforums->input['number'] < 5)
  316.          {
  317.              $ibforums->input['number'] = 5;
  318.          }
  319.          
  320.          if ($ibforums->input['number'] > 50)
  321.          {
  322.              $ibforums->input['number'] = 50;
  323.          }
  324.          
  325.          $type      = 'html';
  326.          $file_name = "pm_archive.html";
  327.          $ctype     = "text/html";
  328.          
  329.          if ($ibforums->input['type'] == 'xls')
  330.          {
  331.              $type      = 'xls';
  332.              $file_name = "xls_importable.txt";
  333.              $ctype     = "text/plain";
  334.          }
  335.          
  336.          $output = "";
  337.          
  338.          //----------------------------------------
  339.          // Start the datafile..
  340.          //----------------------------------------
  341.          
  342.          if ($type == 'html')
  343.          {
  344.              $output .= $this->html->archive_html_header();
  345.          }
  346.          
  347.          require "./sources/lib/post_parser.php";
  348.         
  349.         $this->parser = new post_parser();
  350.          
  351.          //----------------------------------------
  352.          // Get the messages...
  353.          //----------------------------------------
  354.          
  355.          $archive_query = $DB->query("SELECT mg.*, m.name, m.id from ibf_messages mg, ibf_members m WHERE mg.member_id=m.id AND mg.member_id='".$this->member['id']."' AND mg.msg_date > $time_cut".$folder_query." ORDER BY mg.msg_date LIMIT 0,".$ibforums->input['number']);
  356.          
  357.          if ( $DB->get_num_rows($archive_query) )
  358.          {
  359.              while ( $r = $DB->fetch_row($archive_query) )
  360.              {
  361.                  $info = array();
  362.                  
  363.                  $msg_ids[] = $r['msg_id'];
  364.                  
  365.                  $from_member = $DB->query("SELECT id, name FROM ibf_members WHERE id='".$r['from_id']."'");
  366.                  
  367.                  $from_mem = $DB->fetch_row($from_member);
  368.                  
  369.                  $info['msg_date']    = $std->get_date( $r['msg_date'], 'LONG' );
  370.                  $info['msg_title']   = $r['title'];
  371.                  $info['msg_sender']  = $from_mem['name'];
  372.                 $info['msg_content'] = $this->parser->convert( array( 'TEXT'    => $r['message'],
  373.                                                                       'SMILIES' => 0,
  374.                                                                       'CODE'    => $ibforums->vars['msg_allow_code'],
  375.                                                                       'HTML'    => $ibforums->vars['msg_allow_html']
  376.                                                                     )
  377.                                                              );
  378.                  
  379.                  if ($type == 'xls')
  380.                  {
  381.                      $output .= '"'.$this->strip_quotes($info['msg_title']).'","'.$this->strip_quotes($info['msg_date']).'","'.$this->strip_quotes($info['msg_sender']).'","'.$this->strip_quotes($info['msg_content']).'"'."\r";
  382.                  }
  383.                  else
  384.                  {
  385.                      $output .= $this->html->archive_html_entry($info);
  386.                  }
  387.                  
  388.              }
  389.              
  390.              if ($type == 'html')
  391.             {
  392.                 $output .= $this->html->archive_html_footer();
  393.             }
  394.             
  395.             $num_msg = count( $msg_ids );
  396.             
  397.             if ($ibforums->input['delete'] == 'yes')
  398.             {
  399.                 $msg_str = implode( ",", $msg_ids );
  400.                 
  401.                 if (!empty($msg_str))
  402.                 {
  403.                     $DB->query("DELETE FROM ibf_messages WHERE msg_id IN ($msg_str)");
  404.                     
  405.                     $DB->query("UPDATE ibf_members SET msg_total=msg_total-$num_msg WHERE id ='".$this->member['id']."'");
  406.                 }
  407.                 
  408.             }
  409.             
  410.             $this->email->get_template("pm_archive");
  411.             
  412.             $this->email->build_message( array(
  413.                                                 'NAME'         => $this->member['name'],
  414.                                               )
  415.                                         );
  416.                                         
  417.             $this->email->subject = $ibforums->lang['arc_email_subject'];
  418.             $this->email->to      = $this->member['email'];
  419.             $this->email->add_attachment( $output, $file_name, $ctype );
  420.             $this->email->send_mail();
  421.             
  422.             
  423.             $ibforums->lang['arc_complete'] = preg_replace( "/<#NUM#>/", "$num_msg", $ibforums->lang['arc_complete'] );
  424.             
  425.             $this->output .= $this->html->archive_complete();
  426.          
  427.             $this->page_title = $ibforums->lang['t_welcome'];
  428.             $this->nav        = array( "<a href='".$this->base_url."&act=UserCP&CODE=00'>".$ibforums->lang['t_title']."</a>" );
  429.             
  430.         }
  431.         else
  432.         {
  433.             $std->Error( array(  'LEVEL' => 1, 'MSG' => 'no_archive_messages' ) );
  434.         }
  435.          
  436.          
  437.      }
  438.  
  439.      function strip_quotes($text) {
  440.      
  441.          return preg_replace( "/\"/", '\\\"', $text );
  442.          
  443.      }    
  444.      
  445.      /**********************************************************/
  446.      // PREFS:
  447.      //
  448.      // Create/delete/edit messenger folders
  449.      /**********************************************************/
  450.      
  451.      function prefs() {
  452.          global $ibforums, $DB, $std, $print;
  453.          
  454.          $this->output .= $this->html->prefs_header();
  455.          
  456.          $count = 0;
  457.          
  458.          foreach( $this->msg_stats['dir_data'] as $k => $v )
  459.          {
  460.              $extra = "";
  461.              if ($v['id'] == 'in' or $v['id'] == 'sent')
  462.              {
  463.                  $extra = "  ( ".$v['real']." - ".$ibforums->lang['cannot_remove']." )";
  464.              }
  465.              $this->output .= $this->html->prefs_row( array( 'ID' => $v['id'], 'REAL' => $v['real'], 'EXTRA' => $extra ) );
  466.              $count++;
  467.          }
  468.          
  469.          $this->output .= $this->html->prefs_add_dirs();
  470.          
  471.          for ($i = $count; $i < $count+3; $i++)
  472.          {
  473.              $this->output .= $this->html->prefs_row( array( 'ID' => 'dir_'.$i, 'REAL' => '', 'EXTRA' => '' ) );
  474.          }
  475.          
  476.          $this->output .= $this->html->prefs_footer();
  477.          
  478.          $this->page_title = $ibforums->lang['t_welcome'];
  479.          $this->nav        = array( "<a href='".$this->base_url."&act=UserCP&CODE=00'>".$ibforums->lang['t_title']."</a>" );
  480.          
  481.      }
  482.      
  483.      function do_prefs() {
  484.          global $ibforums, $DB, $std, $print;
  485.          
  486.          // Check to ensure than we've not tried to remove the inbox and sent items directories.
  487.          
  488.          if ( ($ibforums->input['sent'] == "") or ($ibforums->input['in'] == "") )
  489.          {
  490.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'cannot_remove_dir' ) );
  491.          }
  492.          
  493.          
  494.          $v_dir = 'in:'.$ibforums->input['in'].'|sent:'.$ibforums->input['sent'];
  495.          
  496.          // Fetch the rest of the dirs
  497.          
  498.          
  499.          $ids = array();
  500.          
  501.          foreach ($ibforums->input as $key => $value)
  502.          {
  503.              if ( preg_match( "/^dir_(\d+)$/", $key, $match ) )
  504.              {
  505.                  if ($ibforums->input[$match[0]])
  506.                  {
  507.                      $v_dir .= '|'.$match[0].':'.trim($ibforums->input[$match[0]]);
  508.                  }
  509.              }
  510.          }
  511.          
  512.          $DB->query("UPDATE ibf_members SET vdirs='$v_dir' WHERE id='".$this->member['id']."'");
  513.          
  514.          $std->boink_it($ibforums->base_url."&act=Msg&CODE=07");
  515.         exit;
  516.          
  517.      }
  518.      
  519.      /**********************************************************/
  520.      // DELETE_MEMBER:
  521.      //
  522.      // Removes a member from address book.
  523.      /**********************************************************/
  524.      
  525.      function del_member() {
  526.          global $ibforums, $DB, $std, $print;
  527.          
  528.          if (!$ibforums->input['MID'])
  529.          {
  530.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_user' ) );
  531.          }
  532.          
  533.          if (! preg_match( "/^(\d+)$/", $ibforums->input['MID'] ) )
  534.          {
  535.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_user' ) );
  536.          }
  537.          
  538.          $DB->query("DELETE FROM ibf_contacts WHERE member_id='".$this->member['id']."' AND contact_id='".$ibforums->input['MID']."'");
  539.          
  540.          $std->boink_it($this->base_url."&act=Msg&CODE=02");
  541.         exit;
  542.     }
  543.     
  544.     /**********************************************************/
  545.      // EDIT_MEMBER:
  546.      //
  547.      // Edit a member from address book.
  548.      /**********************************************************/
  549.      
  550.      function edit_member() {
  551.          global $ibforums, $DB, $std, $print;
  552.          
  553.          if (!$ibforums->input['MID'])
  554.          {
  555.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_user' ) );
  556.          }
  557.          
  558.          if (! preg_match( "/^(\d+)$/", $ibforums->input['MID'] ) )
  559.          {
  560.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_user' ) );
  561.          }
  562.          
  563.          
  564.          $DB->query("SELECT * FROM ibf_contacts WHERE member_id='".$this->member['id']."' AND contact_id='".$ibforums->input['MID']."'");
  565.          $memb = $DB->fetch_row();
  566.          
  567.          if (!$memb['contact_id'])
  568.          {
  569.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_user' ) );
  570.          }
  571.          
  572.          $html = "<select name='allow_msg' class='forminput'>";
  573.          
  574.          if ($memb['allow_msg'])
  575.          {
  576.              $html .= "<option value='yes' selected>{$ibforums->lang['yes']}</option><option value='no'>{$ibforums->lang['no']}";
  577.          }
  578.          else
  579.          {
  580.              $html .= "<option value='yes'>{$ibforums->lang['yes']}</option><option value='no' selected>{$ibforums->lang['no']}";
  581.          }
  582.          
  583.          $html .= "</select>";
  584.          
  585.          $this->output .= $this->html->address_edit( array( 'SELECT' => $html, 'MEMBER' => $memb ) );
  586.          
  587.          
  588.          $this->page_title = $ibforums->lang['t_welcome'];
  589.          $this->nav        = array( "<a href='".$this->base_url."&act=UserCP&CODE=00'>".$ibforums->lang['t_title']."</a>",
  590.                                     "<a href='".$this->base_url."&act=Msg&CODE=02'>".$ibforums->lang['t_book']."</a>"  );
  591.          
  592.      }
  593.      
  594.     /**********************************************************/
  595.      // DO_EDIT_MEMBER:
  596.      //
  597.      // Edit a member from address book.
  598.      /**********************************************************/
  599.      
  600.      function do_edit() {
  601.          global $ibforums, $DB, $std, $print;
  602.          
  603.          if (!$ibforums->input['MID'])
  604.          {
  605.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_user' ) );
  606.          }
  607.          
  608.          if (! preg_match( "/^(\d+)$/", $ibforums->input['MID'] ) )
  609.          {
  610.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_user' ) );
  611.          }
  612.          
  613.          $ibforums->input['allow_msg'] = $ibforums->input['allow_msg'] == 'yes' ? 1 : 0;
  614.          
  615.          $DB->query("SELECT * FROM ibf_contacts WHERE member_id='".$this->member['id']."' AND contact_id='".$ibforums->input['MID']."'");
  616.          $memb = $DB->fetch_row();
  617.          
  618.          if (!$memb['contact_id'])
  619.          {
  620.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_user' ) );
  621.          }
  622.          
  623.          $DB->query("UPDATE ibf_contacts SET contact_desc='".$ibforums->input['mem_desc']."', allow_msg='".$ibforums->input['allow_msg']."' WHERE id='".$memb['id']."'");
  624.          
  625.          $std->boink_it($this->base_url."&act=Msg&CODE=02");
  626.         exit;
  627.          
  628.      }
  629.      
  630.      
  631.          
  632.      /**********************************************************/
  633.      // CONTACT:
  634.      //
  635.      // Shows the address book.
  636.      /**********************************************************/
  637.      
  638.      function contact() {
  639.          global $ibforums, $DB, $std, $print;
  640.          
  641.          $this->output .= $this->html->Address_header();
  642.          
  643.          $DB->query("SELECT * FROM ibf_contacts WHERE member_id='".$this->member['id']."' ORDER BY contact_name ASC");
  644.          
  645.          if ( $DB->get_num_rows() )
  646.          {
  647.          
  648.              $this->output .= $this->html->Address_table_header();
  649.              while ( $row = $DB->fetch_row() )
  650.              {
  651.                  $row['text'] = $row['allow_msg']
  652.                               ? $ibforums->lang['can_contact']
  653.                               : $ibforums->lang['cannot_contact'];
  654.                               
  655.                  $this->output .= $this->html->render_address_row($row);
  656.              }
  657.              $this->output .= $this->html->end_address_table();
  658.              
  659.          }
  660.          else
  661.          {
  662.              $this->output .= $this->html->Address_none();
  663.              
  664.          }
  665.          
  666.          // Do we have a name to enter?
  667.          
  668.          $name_to_enter = "";
  669.          
  670.          if ($ibforums->input['MID'])
  671.          {
  672.              if ( preg_match( "/^(\d+)$/", $ibforums->input['MID'] ) )
  673.              {
  674.                  $DB->query("SELECT name, id FROM ibf_members WHERE id='".$ibforums->input['MID']."'");
  675.                  $memb = $DB->fetch_row();
  676.                  
  677.                  if ($memb['id'])
  678.                  {
  679.                      $name_to_enter = $memb['name'];
  680.                  }
  681.              }
  682.          }
  683.          
  684.          $this->output .= $this->html->address_add($name_to_enter);
  685.          
  686.          $this->page_title = $ibforums->lang['t_welcome'];
  687.          $this->nav        = array( "<a href='".$this->base_url."&act=UserCP&CODE=00'>".$ibforums->lang['t_title']."</a>" );
  688.          
  689.      }
  690.      
  691.      
  692.      /**********************************************************/
  693.      // ADD MEMBER:
  694.      //
  695.      // Adds a member to the addy book.
  696.      /**********************************************************/
  697.      
  698.      function add_member() {
  699.          global $ibforums, $DB, $std, $print;
  700.          
  701.          if (! $ibforums->input['mem_name'])
  702.          {
  703.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_user' ) );
  704.          }
  705.          
  706.          $DB->query("SELECT name, id FROM ibf_members WHERE LOWER(name)='".$ibforums->input['mem_name']."'");
  707.          $memb = $DB->fetch_row();
  708.          
  709.          if (! $memb['id'])
  710.          {
  711.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_user' ) );
  712.          }
  713.          
  714.          //--------------------------------------
  715.          // Do we already have this member in our
  716.          // address book?
  717.          //--------------------------------------
  718.          
  719.          $DB->query("SELECT contact_id FROM ibf_contacts WHERE member_id='".$this->member['id']."' AND contact_id='".$memb['id']."'");
  720.          
  721.          if ( $DB->get_num_rows() )
  722.          {
  723.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'member_in_add_book' ) );
  724.          }
  725.          
  726.          //--------------------------------------
  727.          // Insert it into the DB
  728.          //--------------------------------------
  729.          
  730.          $ibforums->input['allow_msg'] = $ibforums->input['allow_msg'] == 'yes' ? 1 : 0;
  731.          
  732.          $db_string = $std->compile_db_string( array( 
  733.                                                      'member_id'      => $this->member['id'],
  734.                                                      'contact_name'   => $memb['name'],
  735.                                                      'allow_msg'      => $ibforums->input['allow_msg'],
  736.                                                      'contact_desc'   => $ibforums->input['mem_desc'],
  737.                                                      'contact_id'     => $memb['id']
  738.                                             )      );
  739.         
  740.         $DB->query("INSERT INTO ibf_contacts (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")");
  741.         unset($db_string);
  742.         
  743.         // BUH BYE!
  744.         
  745.         $std->boink_it($this->base_url."&act=Msg&CODE=02");
  746.         exit;
  747.     }
  748.          
  749.  
  750.      
  751.      /********************************************************************************************************************/
  752.      // Mutli Act:
  753.      //
  754.      // Removes or moves messages.
  755.      /**********************************************************/
  756.      
  757.      function multi_act() {
  758.          global $ibforums, $DB, $std, $print;
  759.          
  760.          //--------------------------------------
  761.          // Get the ID's to delete
  762.          //--------------------------------------
  763.          
  764.          $ids = array();
  765.          
  766.          foreach ($ibforums->input as $key => $value)
  767.          {
  768.              if ( preg_match( "/^msgid-(\d+)$/", $key, $match ) )
  769.              {
  770.                  if ($ibforums->input[$match[0]])
  771.                  {
  772.                      $ids[] = $match[1];
  773.                  }
  774.              }
  775.          }
  776.          
  777.          $affected_ids = count($ids);
  778.          
  779.          if ( $affected_ids > 0 )
  780.          {
  781.              $id_string = implode( ",", $ids );
  782.              
  783.              if ($ibforums->input['delete'])
  784.              {
  785.                  $DB->query("DELETE FROM ibf_messages WHERE member_id='".$this->member['id']."' AND msg_id IN ($id_string)");
  786.                  $DB->query("UPDATE ibf_members SET msg_total=msg_total-$affected_ids WHERE id='".$this->member['id']."'");
  787.                  $std->boink_it($this->base_url."&act=Msg&CODE=01&VID={$this->vid}");
  788.                  exit;
  789.                  
  790.              }
  791.              else if ($ibforums->input['move'])
  792.              {
  793.                  $DB->query("UPDATE ibf_messages SET vid='".$this->vid."' WHERE member_id='".$this->member['id']."' AND msg_id IN ($id_string)");
  794.                  $std->boink_it($this->base_url."&act=Msg&CODE=01&VID={$this->vid}");
  795.                  exit;
  796.              }
  797.              else
  798.              {
  799.                  $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_msg_chosen' ) );
  800.              }
  801.          }
  802.          else
  803.          {
  804.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_msg_chosen' ) );
  805.          }
  806.          
  807.      }
  808.      
  809.      
  810.      
  811.      /**********************************************************/
  812.      // DELETE MESSAGE:
  813.      //
  814.      // Removes a message.
  815.      // Yes. there is no small print.
  816.      /**********************************************************/
  817.      
  818.      function delete() {
  819.          global $ibforums, $DB, $std, $print;
  820.      
  821.          //--------------------------------------
  822.          // check for a msg ID
  823.          //--------------------------------------
  824.          
  825.          if (!$ibforums->input['MSID'])
  826.          {
  827.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_msg_chosen' ) );
  828.          }
  829.          
  830.          if (! preg_match( "/^\d+$/" , $ibforums->input['MSID'] ) )
  831.          {
  832.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'invalid_use' ) );
  833.          }
  834.          
  835.          //--------------------------------------
  836.          // Delete it from the DB
  837.          //--------------------------------------
  838.          
  839.          $DB->query("DELETE FROM ibf_messages WHERE msg_id='".$ibforums->input['MSID']."' AND member_id='".$this->member['id']."'");
  840.          
  841.          $DB->query("UPDATE ibf_members SET msg_total=msg_total-1 WHERE id='".$this->member['id']."'");
  842.          
  843.          // BYE!
  844.          
  845.          $std->boink_it($this->base_url."&act=Msg&CODE=01&VID={$this->vid}");
  846.          exit;
  847.      }
  848.      
  849.      
  850.      /**********************************************************/
  851.      // VIEW MESSAGE:
  852.      //
  853.      // Views a message, thats it. No, it doesn't do anything else
  854.      // I don't know why. It just does. Accept it and move on dude.
  855.      /**********************************************************/
  856.      
  857.      function view_msg() {
  858.          global $ibforums, $DB, $std, $print;
  859.          
  860.          //--------------------------------------
  861.          // check for a msg ID
  862.          //--------------------------------------
  863.          
  864.          if (!$ibforums->input['MSID'])
  865.          {
  866.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_such_msg' ) );
  867.          }
  868.          
  869.          if (! preg_match( "/^\d+$/" , $ibforums->input['MSID'] ) )
  870.          {
  871.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'invalid_use' ) );
  872.          }
  873.          
  874.          //--------------------------------------
  875.          // Get the message from the DB
  876.          // Check to make sure it exists
  877.          //--------------------------------------
  878.          
  879.          $DB->query("SELECT * FROM ibf_messages WHERE msg_id='".$ibforums->input['MSID']."' and member_id='".$this->member['id']."'");
  880.          $msg = $DB->fetch_row();
  881.          
  882.          if (!$msg['msg_id'])
  883.          {
  884.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_such_msg' ) );
  885.          }
  886.          
  887.          //--------------------------------------
  888.          // Are we tracking this message?
  889.          //--------------------------------------
  890.          
  891.          if ($msg['read_state'] == -1)
  892.          {
  893.          
  894.              $r_time = $std->get_date( $msg['msg_date'], 'LONG' );
  895.              $r_post = "<b>{$ibforums->lang['read_rec_text']} $r_time</b><br>{$msg['message']}<br><br><b>{$this->member['name']} {$ibforums->lang['mem_read_msg']}</b>";
  896.          
  897.              $db_string = $std->compile_db_string( array( 
  898.                                                          'member_id'      => $msg['from_id'],
  899.                                                          'msg_date'       => time(),
  900.                                                          'read_state'     => 0,
  901.                                                          'title'          => $ibforums->lang['read_rec_title'].' '.$msg['title'],
  902.                                                          'message'        => $r_post,
  903.                                                          'from_id'        => $this->member['id'],
  904.                                                          'vid'            => 'in',
  905.                                                          'recipient_id'   => 'N/A',
  906.                                                 )      );
  907.             
  908.             $DB->query("INSERT INTO ibf_messages (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")");
  909.             $new_id = $DB->get_insert_id();
  910.             unset($db_string);
  911.             
  912.             //-----------------------------------------------------
  913.         
  914.             $DB->query("UPDATE ibf_members SET ".
  915.                         "msg_total = msg_total + 1, ".
  916.                         "new_msg = new_msg + 1, ".
  917.                         "msg_from_id='"    .$this->member['id']  .  "', ".
  918.                         "msg_msg_id='"     . $new_id                    .  "' ".
  919.                         "WHERE id='"       . $msg['from_id']            .  "'");
  920.                         
  921.         }
  922.         
  923.         //--------------------------------------
  924.          // Is this an unread message?
  925.          //--------------------------------------
  926.          
  927.          if ($msg['read_state'] < 1)
  928.          {
  929.              $DB->query("UPDATE ibf_messages SET read_state='1' WHERE msg_id='".$ibforums->input['MSID']."'");
  930.          }
  931.          
  932.          
  933.          //--------------------------------------
  934.          // Start formatting the member and msg
  935.          //--------------------------------------
  936.          
  937.          require "./sources/lib/post_parser.php";
  938.         
  939.         $this->parser = new post_parser();
  940.         
  941.          
  942.          $msg['msg_date'] = $std->get_date( $msg['msg_date'], 'LONG' );
  943.          
  944.          
  945.          $DB->query("SELECT g.g_title as member_group, m.id, m.joined, m.name, m.title, m.posts, m.mgroup, m.email, m.signature, m.avatar, m.avatar_size, m.hide_email, m.aim_name, m.icq_number ".
  946.                     "FROM ibf_members m, ibf_groups g WHERE id='".$msg['from_id']."' and g.g_id=m.mgroup");
  947.                     
  948.          $member = $DB->fetch_row();
  949.          
  950.          $member = $this->parse_member( $member, $msg );
  951.          
  952.          $msg['message'] = $this->parser->convert( array( TEXT    => $msg['message'],
  953.                                                          SMILIES => 1,
  954.                                                          CODE    => $ibforums->vars['msg_allow_code'],
  955.                                                          HTML    => $ibforums->vars['msg_allow_html']
  956.                                                        )
  957.                                                 );
  958.                                                 
  959.         if (!$ibforums->vars[SIG_SEP]) $ibforums->vars[SIG_SEP] = "<br><br>--------------------<br>";
  960.                                                 
  961.         if ($this->member['view_sigs'])
  962.         {
  963.             $member['signature'] = $ibforums->vars[SIG_SEP] . $this->parser->convert( array( TEXT    => $member['signature'],
  964.                                                                                        SMILIES => 0,
  965.                                                                                        CODE    => $ibforums->vars['sig_allow_ibc'],
  966.                                                                                        HTML    => $ibforums->vars['sig_allow_html'],
  967.                                                                                        SIGNATURE     => 1,
  968.                                                                                      )
  969.                                                                               );
  970.         }
  971.         else
  972.         {
  973.             $member['signature'] = "";
  974.         }
  975.         
  976.         $member['VID'] = $this->msg_stats['current_id'];
  977.         
  978.         $this->output .= $this->html->Render_msg( array( 
  979.                                                          'msg'    => $msg,
  980.                                                          'member' => $member,
  981.                                                          'jump'   => $this->jump_html
  982.                                                 )      );
  983.                                                
  984.         
  985.         $this->page_title = $ibforums->lang['t_welcome'];
  986.         
  987.         $this->nav        = array( "<a href='".$this->base_url."&act=UserCP&CODE=00'>".$ibforums->lang['t_title']."</a>",
  988.                                    "<a href='".$this->base_url."&act=Msg&CODE=01&VID={$member['VID']}'>".$this->msg_stats['current_dir']."</a>"
  989.                                  );                           
  990.      
  991.      }
  992.      
  993.      /**********************************************************/
  994.      // SEND MESSAGE:
  995.      //
  996.      // Sends a message. Yes, it's that simple. Why so much code?
  997.      // Because typing "send a message to member X" doesnt actually
  998.      // do anything.
  999.      /**********************************************************/
  1000.      
  1001.      function send() {
  1002.          global $ibforums;
  1003.          
  1004.          $ibforums->input['MODE'] ? $this->send_msg() : $this->send_form();
  1005.          
  1006.      }
  1007.      
  1008.      //+-----------------------------------------------------------
  1009.      
  1010.      function send_form($preview=0) {
  1011.          global $ibforums, $DB, $std, $print, $HTTP_POST_VARS;
  1012.          
  1013.          //--------------------------------------
  1014.          // Get some more HTML and words, oh yes.
  1015.          //--------------------------------------
  1016.          
  1017.          $ibforums->lang = $std->load_words($ibforums->lang, 'lang_post', $ibforums->lang_id);
  1018.         
  1019.         require "./Skin/".$ibforums->skin_id."/skin_post.php";
  1020.         $post_html = new skin_post();
  1021.         
  1022.         if ($preview == 1)
  1023.         {
  1024.         
  1025.             require "./sources/lib/post_parser.php";
  1026.         
  1027.             $this->parser = new post_parser();
  1028.             
  1029.             $old_msg = $this->parser->convert( array( TEXT    => $ibforums->input['Post'],
  1030.                                                       SMILIES => 1,
  1031.                                                       CODE    => $ibforums->vars['msg_allow_code'],
  1032.                                                       HTML    => $ibforums->vars['msg_allow_html']
  1033.                                                     )
  1034.                                              );
  1035.                                              
  1036.             $this->output .= $this->html->preview($old_msg);
  1037.         
  1038.         }
  1039.         
  1040.         //--------------------------------------
  1041.          // Load the contacts
  1042.          //--------------------------------------
  1043.          
  1044.          $contacts = "";
  1045.          
  1046.          $DB->query("SELECT * FROM ibf_contacts WHERE member_id='".$this->member['id']."' ORDER BY contact_name");
  1047.          
  1048.          if ( $DB->get_num_rows() )
  1049.          {
  1050.              $contacts = "<select name='from_contact' class='forminput'><option value='-'>".$ibforums->lang['other']."</option>\n<option value='-'>--------------------</option>\n";
  1051.              
  1052.              while ( $entry = $DB->fetch_row() )
  1053.              {
  1054.                  $contacts .= "<option value='".$entry['contact_id']."'>".$entry['contact_name']."</option>\n";
  1055.              }
  1056.              
  1057.              $contacts .= "</select>\n";
  1058.          }
  1059.          else
  1060.          {
  1061.              $contacts = $ibforums->lang['address_list_empty'];
  1062.          }
  1063.          
  1064.          $this->html->class['LANG']['max_msg']     = preg_replace( "/<#MAX_MSG_SIZE#>/", $ibforums->vars['MAX_MSG_SIZE'], $this->html->class['LANG']['max_msg'] );
  1065.          $this->html->class['LANG']['the_max_msg'] = $ibforums->vars['MAX_MSG_SIZE'] * 1024;
  1066.          
  1067.          $name_to_enter = "";
  1068.          $old_message   = "";
  1069.          $old_title     = "";
  1070.         
  1071.         //--------------------------------------
  1072.          // Did we come from a button with a user ID?
  1073.          //--------------------------------------
  1074.          
  1075.          if (!empty($ibforums->input['MID']))
  1076.          {
  1077.              $DB->query("SELECT name, id FROM ibf_members WHERE id='".$ibforums->input['MID']."'");
  1078.              $name = $DB->fetch_row();
  1079.              
  1080.              if ($name['id'])
  1081.              {
  1082.                  $name_to_enter = $name['name'];
  1083.              }
  1084.          }
  1085.          
  1086.          //--------------------------------------
  1087.          // Are we quoting an old message?
  1088.          //--------------------------------------
  1089.          
  1090.          if ($preview == 1)
  1091.          {
  1092.              $old_message = stripslashes($HTTP_POST_VARS['Post']);
  1093.              $old_title   = preg_replace( "/'/", "'", stripslashes($HTTP_POST_VARS['msg_title']) );
  1094.              
  1095.          }
  1096.          else if (!empty($ibforums->input['MSID']))
  1097.          {
  1098.              $DB->query("SELECT message, title from ibf_messages WHERE msg_id='".$ibforums->input['MSID']."' and member_id='".$this->member['id']."'");
  1099.              $old_msg = $DB->fetch_row();
  1100.              if ($old_msg['title'])
  1101.              {
  1102.                  $old_message = '[QUOTE]'.$old_msg['message'].'[/QUOTE]'."\n";
  1103.                  $old_message = preg_replace( "/<br>/", "\n", $old_message );
  1104.                  $old_title   = "Re:".$old_msg['title'];
  1105.                  $old_title   = preg_replace( "/^(?:Re\:){1,}/i", "Re:", $old_title );
  1106.              }
  1107.          }
  1108.          
  1109.          
  1110.          //--------------------------------------
  1111.          // Build up the HTML for the send form
  1112.          //--------------------------------------
  1113.          
  1114.          $this->output .= $this->html->Send_form( array (
  1115.                                                           'CONTACTS'  => $contacts,
  1116.                                                           'MEMBER'    => $this->member,
  1117.                                                           'N_ENTER'   => $name_to_enter,
  1118.                                                           'O_TITLE'   => $old_title,
  1119.                                                 )       );
  1120.          
  1121.          $post_html->class['LANG']['the_max_length'] = $ibforums->vars['MAX_MSG_SIZE'] * 1024;
  1122.          $post_html->class['LANG']['ib_state']       = $ibforums->vars['MSG_ALLOW_CODE'] ? $post_html->class['LANG']['ib_on']   : $post_html->class['LANG']['ib_off'];
  1123.          $post_html->class['LANG']['html_state']     = $ibforums->vars['MSG_ALLOW_HTML'] ? $post_html->class['LANG']['html_on'] : $post_html->class['LANG']['html_off'];
  1124.          
  1125.          $ibforums->lang['the_max_length'] = $ibforums->vars['max_post_length'] * 1024;
  1126.          
  1127.          $this->output .= $post_html->postbox_buttons($old_message);
  1128.          
  1129.          $this->output .= $this->html->send_form_footer();
  1130.          
  1131.          //--------------------------------------
  1132.          // Add in the smilies box
  1133.          //--------------------------------------
  1134.          
  1135.          $show_table = 0;
  1136.         $count      = 0;
  1137.         $smilies    = "<tr align='center'>\n";
  1138.         
  1139.         // Get the smilies from the DB
  1140.         
  1141.         $DB->query("SELECT * FROM ibf_emoticons WHERE clickable='1'");
  1142.         
  1143.         while ($elmo = $DB->fetch_row() ) {
  1144.         
  1145.             $show_table++;
  1146.             $count++;
  1147.             
  1148.             $smilies .= "<td><a href=\"javascript:emoticon('".$elmo['typed']."')\"><img src=\"".$ibforums->vars['EMOTICONS_URL']."/".$elmo['image']."\" alt='smilie' border='0'></a> </td>\n";
  1149.             
  1150.             if ($count == $ibforums->vars['emo_per_row']) {
  1151.                 $smilies .= "</tr>\n\n<tr align='center'>";
  1152.                 $count = 0;
  1153.             }
  1154.         }
  1155.         
  1156.         if ($count != $ibforums->vars['emo_per_row']) {
  1157.             for ($i = $count ; $i < $ibforums->vars['emo_per_row'] ; ++$i) {
  1158.                 $smilies .= "<td> </td>\n";
  1159.             }
  1160.             $smilies .= "</tr>";
  1161.         }
  1162.         
  1163.         $table = $post_html->smilie_table();
  1164.         
  1165.         if ($show_table != 0) {
  1166.             $table = preg_replace( "/<!--THE SMILIES-->/", $smilies, $table );
  1167.             $this->output = preg_replace( "/<!--SMILIE TABLE-->/", $table, $this->output );
  1168.         }
  1169.         
  1170.         
  1171.         $this->page_title = $ibforums->lang['t_welcome'];
  1172.          $this->nav        = array( "<a href='".$this->base_url."&act=UserCP&CODE=00'>".$ibforums->lang['t_title']."</a>" );
  1173.         
  1174.          
  1175.      }
  1176.      
  1177.      
  1178.      
  1179.      
  1180.      
  1181.      //+-----------------------------------------------------------
  1182.      
  1183.      
  1184.      
  1185.      
  1186.      
  1187.      function send_msg() {
  1188.          global $ibforums, $DB, $std, $print;
  1189.          
  1190.          $ibforums->input['from_contact'] = $ibforums->input['from_contact'] ? $ibforums->input['from_contact'] : '-';
  1191.          
  1192.          //----------------------------------------------------------------
  1193.          if ( strlen($ibforums->input['msg_title']) < 2 )
  1194.          {
  1195.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_msg_title' ) );
  1196.          }
  1197.          //----------------------------------------------------------------
  1198.          if ( strlen($ibforums->input['Post']) < 2 )
  1199.          {
  1200.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_msg' ) );
  1201.          }
  1202.          //----------------------------------------------------------------
  1203.          if ($ibforums->input['from_contact'] == '-' and $ibforums->input['entered_name'] == "")
  1204.          {
  1205.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_chosen_member' ) );
  1206.          }
  1207.          //----------------------------------------------------------------
  1208.          
  1209.          //--------------------------------------
  1210.          // Attempt to get the reciepient details
  1211.          //--------------------------------------
  1212.          
  1213.          $to_member = array();
  1214.          
  1215.          if ($ibforums->input['from_contact'] == '-')
  1216.          {
  1217.              $query = "LOWER(name)='".$ibforums->input['entered_name']."'";
  1218.          }
  1219.          else
  1220.          {
  1221.              $query = "id='".$ibforums->input['from_contact']."'";
  1222.          }
  1223.          
  1224.          $DB->query("SELECT name, id, view_pop, mgroup FROM ibf_members WHERE ".$query);
  1225.          $to_member = $DB->fetch_row();
  1226.          
  1227.          if (empty($to_member['id']))
  1228.          {
  1229.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_to_member' ) );
  1230.          }
  1231.          
  1232.          //--------------------------------------
  1233.          // Can the reciepient use the PM system?
  1234.          //--------------------------------------
  1235.          
  1236.          $DB->query("SELECT g_use_pm FROM ibf_groups WHERE g_id='".$to_member['mgroup']."'");
  1237.          $allow = $DB->fetch_row();
  1238.          
  1239.          if ($allow['g_use_pm'] != 1)
  1240.          {
  1241.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_usepm_member' ) );
  1242.          }
  1243.          
  1244.          //--------------------------------------
  1245.          // Has the reciepient blocked us?
  1246.          //--------------------------------------
  1247.          
  1248.          $DB->query("SELECT contact_id, allow_msg FROM ibf_contacts WHERE contact_id='".$this->member['id']."' AND member_id='".$to_member['id']."'");
  1249.          $can_msg = $DB->fetch_row();
  1250.          
  1251.          if ( (isset($can_msg['contact_id'])) and ($can_msg['allow_msg'] != 1) )
  1252.          {
  1253.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'msg_blocked' ) );
  1254.          }
  1255.          
  1256.          //--------------------------------------
  1257.          // Do we have enough room to store a
  1258.          // saved copy?
  1259.          //--------------------------------------
  1260.          
  1261.          if ($ibforums->input['add_sent'] and $ibforums->vars['max_messages'])
  1262.          {
  1263.             if ( ($this->msg_stats['msg_total'] + 1) >= $ibforums->vars['max_messages'] )
  1264.             {
  1265.                 $std->Error( array( 'LEVEL' => 1, 'MSG' => 'max_message_from' ) );
  1266.             }
  1267.          }
  1268.          
  1269.          //--------------------------------------
  1270.          // Is this a preview?
  1271.          //--------------------------------------
  1272.          
  1273.          if ($ibforums->input['preview'] != "")
  1274.          {
  1275.              $ibforums->input['MID'] = $to_member['id'];
  1276.              $this->send_form(1);
  1277.              return;
  1278.          }
  1279.          
  1280.          //--------------------------------------
  1281.          // Sort out tracking and pop us status
  1282.          //--------------------------------------
  1283.          
  1284.          $show_popup =  $to_member['view_pop'];
  1285.          
  1286.          $track_id = 0;
  1287.          
  1288.          if ($ibforums->input['add_tracking'])
  1289.          {
  1290.              $track_id = -1;
  1291.          }
  1292.          
  1293.          //--------------------------------------
  1294.          // Get the recipient msg_stats
  1295.          //--------------------------------------
  1296.          
  1297.          $DB->query("SELECT msg_total FROM ibf_members WHERE id='".$to_member['id']."'");
  1298.          $to_msg_stats = $DB->fetch_row();
  1299.          
  1300.          //--------------------------------------
  1301.          // Does the target member have enough room
  1302.          // in their inbox for a new message?
  1303.          //--------------------------------------
  1304.          
  1305.         if ( (($to_msg_stats['msg_total']) >= $ibforums->vars['max_messages']) and ($ibforums->vars['max_messages'] != "") )
  1306.         {
  1307.             $std->Error( array( 'LEVEL' => 1, 'MSG' => 'max_message_to' ) );
  1308.         }
  1309.         
  1310.         //--------------------------------------
  1311.          // Enter the info into the DB
  1312.          // Target user side.
  1313.          //--------------------------------------
  1314.          
  1315.          $db_string = $std->compile_db_string( array( 
  1316.                                                       'member_id'      => $to_member['id'],
  1317.                                                       'msg_date'       => time(),
  1318.                                                       'read_state'     => $track_id,
  1319.                                                       'title'          => $ibforums->input['msg_title'],
  1320.                                                       'message'        => $ibforums->input['Post'],
  1321.                                                       'from_id'        => $this->member['id'],
  1322.                                                       'vid'            => 'in',
  1323.                                                       'recipient_id'   => $to_member['id'],
  1324.                                              )      );
  1325.         
  1326.         $DB->query("INSERT INTO ibf_messages (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")");
  1327.         $new_id = $DB->get_insert_id();
  1328.         unset($db_string);
  1329.         
  1330.         //-----------------------------------------------------
  1331.         
  1332.         $DB->query("UPDATE ibf_members SET ".
  1333.                     "msg_total = msg_total + 1, "                    .
  1334.                     "new_msg = new_msg + 1, "                        .
  1335.                     "msg_from_id='"     .$this->member['id']         .  "', ".
  1336.                     "msg_msg_id='"      . $new_id                    .  "', ".
  1337.                     "show_popup='"      . $show_popup                .  "' ".
  1338.                     "WHERE id='"        . $to_member['id']           .  "'");
  1339.          
  1340.          //-----------------------------------------------------
  1341.          // Add the data to the current members DB if we are
  1342.          // adding it to our "sent items" folder
  1343.          //-----------------------------------------------------
  1344.          
  1345.          if ($ibforums->input['add_sent'])
  1346.          {
  1347.          
  1348.             $DB->query("UPDATE ibf_members SET ".
  1349.                         "msg_total = msg_total + 1 ".
  1350.                         "WHERE id='" . $this->member['id'] . "'");
  1351.                         
  1352.             $db_string = $std->compile_db_string( array( 
  1353.                                                          'member_id'      => $this->member['id'],
  1354.                                                          'msg_date'       => time(),
  1355.                                                          'read_state'     => 0,
  1356.                                                          'title'          => $ibforums->lang['saved_sent_msg'].' '.$ibforums->input['msg_title'],
  1357.                                                          'message'        => $ibforums->input['Post'],
  1358.                                                          'from_id'        => $this->member['id'],
  1359.                                                          'vid'            => 'sent',
  1360.                                                          'recipient_id'   => $to_member['id'],
  1361.                                                 )      );
  1362.             
  1363.             
  1364.             $DB->query("INSERT INTO ibf_messages (" .$db_string['FIELD_NAMES']. ") VALUES (". $db_string['FIELD_VALUES'] .")");
  1365.             unset($db_string);
  1366.         }
  1367.         
  1368.         $text = preg_replace( "/<#FROM_MEMBER#>/"   , $this->member['name'] , $ibforums->lang['sent_text'] );
  1369.         $text = preg_replace( "/<#TO_MEMBER#>/"     , $to_member['name']    , $text );
  1370.         $text = preg_replace( "/<#MESSAGE_TITLE#>/" , $ibforums->input['msg_title'], $text );
  1371.         
  1372.         $print->redirect_screen( $text , "&act=Msg&CODE=01" );
  1373.          
  1374.      }
  1375.      
  1376.      
  1377.      /**********************************************************/
  1378.      // MSG LIST:
  1379.      //
  1380.      // Views the inbox / folder of choice
  1381.      /**********************************************************/
  1382.      
  1383.      function msg_list() {
  1384.          global $ibforums, $DB, $std, $print;
  1385.          
  1386.          $sort_key    = $ibforums->input['sort_key']   ? $ibforums->input['sort_key']   : 'msg_date';
  1387.          $sort_order  = $ibforums->input['sort_order'] ? $ibforums->input['sort_order'] : 'Z-A';
  1388.          
  1389.          $sort_order  = 'Z-A' ? 'DESC' : 'ASC';
  1390.          
  1391.          //---------------------------------------------
  1392.          // Get the number of messages we have in total.
  1393.          //---------------------------------------------
  1394.          
  1395.          $DB->query("SELECT COUNT(*) as msg_total FROM ibf_messages WHERE member_id='".$this->member['id']."'");
  1396.          $total = $DB->fetch_row();
  1397.          
  1398.          $total['msg_total'] = $total['msg_total'] > 0 ? $total['msg_total'] : 0;
  1399.          
  1400.          if ($ibforums->member['msg_total'] == "")
  1401.          {
  1402.              $DB->query("UPDATE ibf_members SET msg_total='".$total['msg_total']."' WHERE id='".$this->member['id']."'");
  1403.          }
  1404.          
  1405.          //---------------------------------------------
  1406.          // Make sure we've not exceeded our alloted allowance.
  1407.          //---------------------------------------------
  1408.          
  1409.          $info['full_messenger'] = "";
  1410.          $info['full_percent']   = "";
  1411.          $info['space_free']     = "Unlimited";
  1412.          $info['total_messages'] = $total['msg_total'];
  1413.          
  1414.          if ($ibforums->vars['max_messages'] > 0)
  1415.          {
  1416.              if ($total['msg_total'] >= $ibforums->vars['max_messages'])
  1417.              {
  1418.                  $info['full_messenger'] = "<span id='highlight'>".$ibforums->lang['folders_full']."</span>";
  1419.              }
  1420.              
  1421.              $info['full_percent'] = $total['msg_total'] ? sprintf( "%.0f", ( ($total['msg_total'] / $ibforums->vars['max_messages']) * 100) ) : 0;
  1422.              $info['full_percent'] = "(". $info['full_percent'] .'% '. $ibforums->lang['total_capacity'] . ")";
  1423.              $info['space_free']   = $ibforums->vars['max_messages'] - $total['msg_total'];
  1424.          }
  1425.          
  1426.          
  1427.          //---------------------------------------------
  1428.          // Print the header
  1429.          //---------------------------------------------
  1430.          
  1431.          if ($this->vid == 'sent')
  1432.          {
  1433.              $ibforums->lang['message_from'] = $ibforums->lang['message_to'];
  1434.              
  1435.              $DB->query("SELECT m.*, mp.name as from_name FROM ibf_messages m, ibf_members mp WHERE member_id='".$this->member['id']."' AND vid='".$this->vid."' and mp.id=m.recipient_id ORDER BY $sort_key $sort_order");
  1436.          
  1437.          }
  1438.          else
  1439.          {
  1440.              $DB->query("SELECT m.*, mp.name as from_name FROM ibf_messages m, ibf_members mp WHERE member_id='".$this->member['id']."' AND vid='".$this->vid."' and mp.id=m.from_id ORDER BY $sort_key $sort_order");
  1441.          }
  1442.          
  1443.          $this->output .= $this->html->inbox_table_header( $this->msg_stats['current_dir'], $info );
  1444.          
  1445.          //---------------------------------------------
  1446.          // Get the messages
  1447.          //---------------------------------------------
  1448.          
  1449.          
  1450.          if ( $DB->get_num_rows() )
  1451.          {
  1452.              while( $row = $DB->fetch_row() )
  1453.              {
  1454.                  $row['icon'] = $row['read_state'] == 1 ? $ibforums->skin['M_READ'] : $ibforums->skin['M_UNREAD'];
  1455.                  $row['date'] = $std->get_date( $row['msg_date'] , 'LONG' );
  1456.                  
  1457.                  if ($this->vid != 'sent')
  1458.                  {
  1459.                      $row['add_to_contacts'] = "[ <a href='{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}?s={$ibforums->session_id}&act=Msg&CODE=02&MID={$row['from_id']}'>{$ibforums->lang[add_to_book]}</a> ]";
  1460.                  }
  1461.                  else
  1462.                  {
  1463.                      $row['from_id'] = $row['recipient_id'];
  1464.                  }
  1465.                  
  1466.                  $d_array = array( 'msg' => $row, 'member' => $this->member, 'stat' => $this->msg_stats );
  1467.                  
  1468.                  $this->output .= $this->html->inbox_row( $d_array );
  1469.              }
  1470.          }
  1471.          else
  1472.          {
  1473.              $this->output .= $this->html->No_msg_inbox();
  1474.          }
  1475.          
  1476.          $sorted_by = 'from_' . $sort_key;
  1477.          $this->output .= $this->html->end_inbox( $this->jump_html );
  1478.          
  1479.          //---------------------------------------------
  1480.          // Update the message stats if we have to
  1481.          //---------------------------------------------
  1482.          
  1483.          if ($this->msg_stats['current_id'] == 'in')
  1484.          {
  1485.              $DB->query("UPDATE ibf_members SET ".
  1486.                           "new_msg='0' ".
  1487.                           "WHERE id='".$this->member['id']."'");
  1488.          }
  1489.          
  1490.          $this->page_title = $ibforums->lang['t_welcome'];
  1491.          $this->nav        = array( "<a href='".$this->base_url."&act=UserCP&CODE=00'>".$ibforums->lang['t_title']."</a>" );
  1492.          
  1493.          
  1494.      }
  1495.  
  1496.  
  1497. //+------------------------------------------------------------------------------------
  1498.  
  1499.     /*********************************************************************/
  1500.     // Parse the member info
  1501.     /*********************************************************************/
  1502.     
  1503.     function parse_member($member=array(), $row=array()) {
  1504.         global $ibforums, $std, $DB;
  1505.         
  1506.         $member['name'] = "<a href='{$this->base_url}&act=Profile&CODE=03&MID={$member['id']}'>{$member['name']}</a>";
  1507.     
  1508.         $member['avatar'] = $std->get_avatar( $member['avatar'], $ibforums->member['view_avs'], $member['avatar_size'] );
  1509.         
  1510.         $member['MEMBER_JOINED'] = $ibforums->lang['m_joined'].' '.$std->get_date( $member['joined'], 'JOINED' );
  1511.         
  1512.         $member['MEMBER_GROUP'] = $ibforums->lang['m_group'].' '.$member['member_group'];
  1513.         
  1514.         $member['MEMBER_POSTS'] = $ibforums->lang['m_posts'].' '.$member['posts'];
  1515.         
  1516.         $member['PROFILE_ICON'] = "<a href='{$this->base_url}&act=Profile&CODE=03&MID={$member['id']}'>{$ibforums->skin['P_PROFILE']}</a> ";
  1517.         
  1518.         $member['MESSAGE_ICON'] = "<a href='{$this->base_url}&act=Msg&CODE=04&MID={$member['id']}'>{$ibforums->skin['P_MSG']}</a> ";
  1519.         
  1520.         if (!$member['hide_email']) {
  1521.             $member['EMAIL_ICON'] = "<a href='{$this->base_url}&act=Mail&CODE=00&MID={$member['id']}'>{$ibforums->skin['P_EMAIL']}</a> ";
  1522.         }
  1523.         
  1524.         if ( $member['website'] and $member['website'] = preg_match( "/^http:\/\/\S+$/", $member['WEBSITE'] ) ) {
  1525.             $member['WEBSITE_ICON'] = "<a href='{$member['website']}' target='_blank'>{$ibforums->skin['P_WEBSITE']}</a> ";
  1526.         }
  1527.         
  1528.         if ($member['icq_number']) {
  1529.             $member['ICQ_ICON'] = "<a href=\"javascript:PopUp('{$this->base_url}&act=ICQ&MID={$member['id']}','Pager','450','330','0','1','1','1')\">{$ibforums->skin[P_ICQ]}</a> ";
  1530.         }
  1531.         
  1532.         if ($member['aim_name']) {
  1533.             $member['AOL_ICON'] = "<a href=\"javascript:PopUp('{$this->base_url}&act=AOL&MID={$member['id']}','Pager','450','330','0','1','1','1')\">{$ibforums->skin[P_AOL]}</a> ";
  1534.         }
  1535.         
  1536.         //-----------------------------------------------------
  1537.         
  1538.         return $member;
  1539.     
  1540.     }
  1541.  
  1542.  
  1543.         
  1544. }
  1545.  
  1546. ?>
  1547.